import { defineStore } from 'pinia'
import { ITheme } from '@/store/theme/interface'
import { CacheService } from '@/utils/cache'
// import { DictService } from '@/modules/system'

export const appStore = defineStore('appStore', {
	state: () => ({
		// sidebar 是否展开
		sidebarOpened: CacheService.getSidebarOpened(),
		// 国际化
		language: CacheService.getLanguage(),
		// 组件大小
		componentSize: CacheService.getComponentSize(),
		// 字典列表
		dictList: [],
		// 主题
		theme: CacheService.getTheme(),
		layout: {
			//50：头部导航高度 40：tab导航高度 20：主窗体margin 15：主窗体padding
			mainBodyHeight: document.body.clientHeight - 50 - 40 - (20 * 2) - (15 * 2)
		}
	}),
	actions: {
		removeLoading() {
			document.getElementById("preloader")?.remove();
		},
		setSidebarOpened() {
			this.sidebarOpened = !this.sidebarOpened
			CacheService.setSidebarOpened(this.sidebarOpened)
		},
		setLanguage(locale: string) {
			this.language = locale
			CacheService.setLanguage(locale)
		},
		setComponentSize(size: string) {
			this.componentSize = size
			CacheService.setComponentSize(size)
		},
		// async getDictListAction() {
		// 	const list = await DictService.useDictTypeAllApi()
		// 	this.dictList = list || []
		// },
		setTheme(theme: ITheme) {
			this.theme = theme
			CacheService.setTheme(theme)
		}
	}
})
